package _04Dom4j;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.util.ArrayList;
import java.util.List;

public class Test {
    public static void main(String[] args) throws DocumentException {
        SAXReader saxReader = new SAXReader();
        Document read = saxReader.read("day14\\src\\_04Dom4j\\contact.xml");

        Element rootElement = read.getRootElement();
        List<Element> elements = rootElement.elements();
        List<Contact> list = new ArrayList<>();
        //contact标签
        for (Element element : elements) {
            //子标签
            int id =Integer.parseInt(element.attributeValue("id"));
            boolean vip =Boolean.parseBoolean(element.attributeValue("vip"));
            String name = element.element("name").getText();
            String gender = element.element("gender").getText();
            String email = element.element("email").getText();
            list.add(new Contact(id,vip,name,gender,email));

        }
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }
    }
}
